Margin Trading
Margin trading refers to using borrowed funds to pay for a trade. Margin trading allows traders to open a position in the market without paying the entire price up-front.
Before delving deeper into Margin trading, below are some terms related to Margin trading you should be familiar with.
| Term | Explanation |
|---|---|
| Leverage | Leverage refers to the use of borrowed funds to pay for a trade.For example, if a trader wishes to buy a $1000 token for 5x leverage, they will only have to pay $200 upfront, and the exchange or broker will pay the remaining amount. |
| Equity | The value of an account based on the current market price minus the borrowed amount is known as equity. |
| Margin | Because of the real-time fluctuation in the Crypto market, the equity level will also fluctuate. If the equity level drops below a certain level, the trader may have to sell some or all their positions or add more funds to their account. |
| Margin Call | If the equity level drops below the set threshold level the trader gets a notification known as a Margin call. |
| Collateral | The assets that are available in the user’s account are used as collateral. |
| Liquidation | If the trader fails to meet a margin call the exchange can sell its assets to pay this loan. This process is known as liquidation. |
Let us try to understand these concepts more with an example.
Assume we bought a crypto token worth $1000, with 5x leverage. In this case, you will be paying $200 and the exchange or broker will pay $800.
| Spot | Margin | |
|---|---|---|
| Amount that the trader Invested($) | 200 | 200 |
| Borrowed Amount($) | - | 800 |
| Total Amount Invested($) | 200 | 200+800 = 1000 |
| Increase of 10% | 220 | 1100 |
| Profit($) | 220 - 200 = $20 | 1100 - 800 - 200 = $100 |
In the case above, you will make a profit five times Spot trading because you have invested 5x the amount up-front.
But, Margin trading is a two-edged sword. So, instead of increasing by 10%, if the token's value drops by 10%, you will lose 5x the amount.
For example,
| Spot | Margin | |
|---|---|---|
| Amount that the trader Invested($) | 200 | 200 |
| Borrowed Amount($) | - | 800 |
| Total Amount Invested($) | 200 | 200+800 = 1000 |
| Decrease of 10% | 180 | 900 |
| Loss($) | 180 - 200 = - $20 | 900 - 800 - 200 = - $100 |
First Margin Order on CoinDCX API
To place a margin order, follow these steps:
- Use the following endpoint to place your margin order.
https://api.coindcx.com/exchange/v1/margin/create
- Specify the following details in the body of your code:
| Parameter | Required | Description |
|---|---|---|
| market | Yes | Indicates the pair for which the order is being placed. |
| Quantity | Yes | The quantity of the asset to be traded. |
| price | Yes | Price of the asset per unit. |
| leverage | No | Refers to the capital borrowed from the exchange or broker to increase the returns. |
| side | Yes | Indicates the side for which you are placing the order. Acceptable values are:
|
| stop_price | No | Indicates the price at which the order stops. |
| order_type | Yes | Indicates the order type. The following order types can be used:
|
| trailing_sl | No | Indicates an order placed with trailing stop-loss. |
| target_price | No | Indicates the price at which you wish to either buy, sell, or close the order. |
| ecode | Yes | Indicates the exchange code in which the order will be placed. |
| timestamp | Yes | Indicates the timestamp at which the request was generated. |
- Once the order has been placed, you will receive a confirmation in the following format.
[
{
"id": "30b5002f-d9c1-413d-8a8d-0fd32b054c9c",
"side": "sell",
"status": "init",
"market": "XRPBTC",
"order_type": "limit_order",
"trailing_sl": false,
"trail_percent": null,
"avg_entry": 0,
"avg_exit": 0,
"fee": 0.02,
"entry_fee": 0,
"exit_fee": 0,
"active_pos": 0,
"exit_pos": 0,
"total_pos": 0,
"quantity": 200,
"price": 0.000026,
"sl_price": 0.00005005,
"target_price": 0,
"stop_price": 0,
"pnl": 0,
"initial_margin": 0.00520208,
"interest": 0.05,
"interest_amount": 0,
"leverage": 1,
"result": null,
"created_at": 1568122929782,
"updated_at": 1568122929782,
"orders": [
{
"id": 164993,
"order_type": "limit_order",
"status": "initial",
"market": "XRPBTC",
"side": "sell",
"avg_price": 0,
"total_quantity": 200,
"remaining_quantity": 200,
"price_per_unit": 0.000026,
"timestamp": 1568122929880.75,
"fee": 0.02,
"fee_amount": 0,
"filled_quantity": 0,
"bo_stage": "stage_entry",
"cancelled_quantity": 0,
"stop_price": 0,
}
],
}
]
You can use the id parameter in the response to,
- Edit Order Details
- Cancel an Order
- Retrieve data for an order
To know more about specific endpoints for these, refer to the API Documentation.